<template>
  <div class="kefu">
    <div class="left1" v-if="isShowCode">
      <p>江苏铭创</p>
      <p>为您提供VIP服务</p>
      <img
        style="width: 10.71rem; height: 10.71rem"
        src="https://njmcsw.oss-cn-beijing.aliyuncs.com/guanwang/kefuCode.png"
        alt=""
      />
      <p style="color: #b9b9b9">扫码添加客服微信</p>
    </div>
    <div class="left2" v-if="isShowPhone">
      <p style="color: #131313">售前电话</p>
      <p style="color: #d00b17">400-025-6968</p>
    </div>
    <div class="right">
      <!-- <div
        :class="[{ item: true }, { active: isChange === 1 }]"
        @click="onShow(1)"
      >
        <img
          v-if="isChange === 1"
          class="weixin"
          src="@/assets/icon/weixinW.png"
          alt=""
        />
        <img v-else class="weixin" src="@/assets/icon/weixinR.png" alt="" />
        <span>添加微信</span>
      </div>
      <div
        :class="[{ item: true }, { active: isChange === 2 }]"
        @click="onShow(2)"
      >
        <img
          v-if="isChange === 2"
          class="phone"
          src="@/assets/icon/phoneW.png"
          alt=""
        />
        <img v-else class="phone" src="@/assets/icon/phoneR.png" alt="" />
        <span>拨打电话</span>
      </div> -->
      <div
        :class="[{ item: true }, { active: isChange === 3 }]"
        @click="onShow(3)"
      >
        <img
          v-if="isChange === 3"
          class="jiantou"
          src="@/assets/icon/jiantouW.png"
          alt=""
        />
        <img v-else class="jiantou" src="@/assets/icon/jiantouR.png" alt="" />
        <span>返回顶部</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "kefu",
  data() {
    return {
      isShowCode: false,
      isShowPhone: false,
      isChange: 0,
    };
  },
  methods: {
    onShow(type) {
      this.isChange = type;
      if (type === 1) {
        this.isShowPhone = false;
        this.isShowCode = !this.isShowCode;
      } else if (type === 2) {
        this.isShowCode = false;
        this.isShowPhone = !this.isShowPhone;
      } else {
        this.isShowCode = false;
        this.isShowPhone = false;
        // scrollTo(0,0);
        // 缓慢回滚到页面顶部
        var timer = null;
        cancelAnimationFrame(timer);

        timer = requestAnimationFrame(function fn() {
          var oTop =
            document.body.scrollTop || document.documentElement.scrollTop;

          if (oTop > 0) {
            scrollBy(0, -100);

            timer = requestAnimationFrame(fn);
          } else {
            cancelAnimationFrame(timer);
          }
        });
      }
    },
  },
};
</script>

<style scoped lang="scss">
.kefu {
  position: fixed;
  right: 0;
  bottom: 10rem;
  margin-right: 1.29rem;
  display: flex;

  .left1 {
    margin-right: 0.21rem;
    background-color: #ffffff;
    width: 14.07rem;
    height: 18.43rem;
    border-radius: 0.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 0.7rem;

    p {
      color: #131313;
      font-size: 1.21rem;
      font-weight: 500;
      line-height: 2rem;
    }
  }

  .left2 {
    margin: 8.6rem 0.21rem 0 0;
    padding-left: 1.61rem;
    background-color: #ffffff;
    width: 14.07rem;
    height: 6.57rem;
    border-radius: 0.5rem;
    display: flex;
    flex-direction: column;
    justify-content: center;

    p {
      font-size: 1.21rem;
      font-weight: 500;
      line-height: 2rem;
    }
  }

  .right {
    width: 7.21rem;
    border-radius: 0.5rem;
    background-color: #ffffff;
    padding-top: 1rem;

    .item {
      height: 6.29rem;
      display: flex;
      flex-direction: column;
      align-items: center;
      padding-top: 0.71rem;
      margin-bottom: 1.43rem;

      span {
        color: #d00b17;
        font-size: 1.29rem;
        line-height: 1.79rem;
      }

      .weixin {
        width: 3.07rem;
        height: 2.5rem;
        margin-bottom: 0.7rem;
      }

      .phone {
        width: 2.86rem;
        height: 3.07rem;
        margin-bottom: 0.5rem;
      }

      .jiantou {
        width: 3.14rem;
        height: 3.14rem;
        margin-bottom: 0.4rem;
      }
    }
  }
}

// 切换背景色
.active {
  background-color: #d00b17;

  span {
    color: #ffffff !important;
  }
}
</style>
